# 基础使用
from bs4 import BeautifulSoup

# soup = BeautifulSoup("<p>hello<b>world<i>china", features='lxml')

# print(soup.prettify())
html = """
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>aTitle发发发1</title>
</head>
<body>
    <ul>
        <li id="item1" class="item">醒醒啦1</li>
        <li id="item2" class="item">醒醒啦2</li>
        <li id="item3" class="item">醒醒啦3</li>
        <li id="item4" class="item">醒醒啦4</li>
        <li id="item5" class="item">醒醒啦5</li>
    </ul>
    <p>
        hello
        i
        am
        iron
        man
    </p>
    <div id="target"><p id="p0"> 醒醒啦 </p></div>

</body>
</html>
"""
soup = BeautifulSoup(html, features='lxml')

title = soup.find("title")
print(title.text)

items = soup.find_all("li", attrs={"class": "item"})
for item in items:
    print(item.text, item.attrs["id"])

target = soup.find("div", attrs={"id": "target"})
inner_p = target.find("p")
print(inner_p.text.strip(), inner_p.has_attr("id"), inner_p.get("name", "p"))

